home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 1144 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.9 KB  |  54 lines

  1. Path: fido.asd.sgi.com!austern
  2. From: Rich Paul <linguist@cyberspy.com>
  3. Newsgroups: comp.std.c++
  4. Subject: Re: Is RTTI required if polymorphic constructor exists
  5. Date: 17 Apr 1996 13:23:24 PDT
  6. Organization: Technical Resource Connection
  7. Approved: austern@isolde.mti.sgi.com
  8. Message-ID: <31755193.113D@cyberspy.com>
  9. References: <4kng7f$kt9@nuscc.nus.sg> <4kr21b$6ar@mulga.cs.mu.OZ.AU> <4l30l2$31v@nuscc.nus.sg>
  10. NNTP-Posting-Host: isolde.mti.sgi.com
  11. X-Original-Date: Wed, 17 Apr 1996 16:16:19 -0400
  12. X-Mailer: Mozilla 2.01Gold (WinNT; I)
  13. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  14.     iQBVAwUBMXVTPky4NqrwXLNJAQGOhwH/XG5Fzh8iGURUOkzafixAbf9biyypwKWb
  15.     vfGBGyK3HontNlMbpLN1MnhNlnv6X54L98Yz5Bho4MjB4ToxCQFTRw==
  16.     =kHXL
  17. Originator: austern@isolde.mti.sgi.com
  18.  
  19. Satrajit Sujit Ghosh wrote:
  20. >         Would it be possible to illustrate efficient, convenient and
  21. > pratical use of the RTTI functions?
  22.  
  23. Hmmm ... well, this comes in handy:
  24.  
  25. ostream &operator << ( ostream &os, const exception &e )
  26. {
  27.     return os << endl
  28.           << "Exception: " << typeid(e).name() << endl
  29.               << "Message:   " << e.what() << endl;
  30. };
  31.  
  32. Since the typename of the exception carries some of the most relevent 
  33. information about the exception, why not use it ... of course, the
  34. same thing could be done with virtual functions.
  35.  
  36. The rule of thumb I've been told is not to use RTTI unless there's 
  37. just no other way to do it.
  38.  
  39.  
  40. -- 
  41. #include <legalbs/standarddisclaimer>
  42. Rich Paul                |  If you like what I say, tell my
  43. C++, OOD, OOA, OOP,      |  employer, but if you don't,
  44. OOPs, I forgot one ...   |  don't blame them.  ;->
  45. ---
  46. [ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
  47.                 newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  48.   comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  49.   Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  50.   Comments? mailto:std-c++-request@ncar.ucar.edu 
  51. ]
  52.